
using UnityEngine;
using WooEngine.Data.Base;
using WooEngine.Extends.Main;
using WooEngine.Persistence;

namespace Assets.Framework.WooEngineExtends.Config
{
    public class AppConfigProxy : AbstractDataProxy<AppConfigData, string>
    {
        public const string DefaultName = "AppConfigProxy";

        private const string m_dbKey = "AppConfigData";

        public AppConfigProxy() : base(DefaultName, new AppConfigData())
        {
            if (DBManager.Instance.IsHasKey(GameManager.GameDBName, m_dbKey))
            {
                this.GetData().Initialize(DBManager.Instance.Load<string>(GameManager.GameDBName, m_dbKey));
            }
            else
            {
                DBManager.Instance.Save<string>(GameManager.GameDBName, m_dbKey, JsonUtility.ToJson( this.GetData()));
            }
        }

        public void SaveAppConfig()
        {
            DBManager.Instance.Save<string>(GameManager.GameDBName, m_dbKey, JsonUtility.ToJson(this.GetData()));
        }

        public int Lang()
        {
            return this.GetData().lang;
        }

        public void SetLang(int lang)
        {
            this.GetData().lang = lang;
            SaveAppConfig();
        }

    }
}